package com.pactera.madp.cp.controller.sidebar.track;

import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.common.security.annotation.Inner;
import com.pactera.madp.cp.api.dto.track.BehaviorTrackDto;
import com.pactera.madp.cp.service.BehaviorTrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController(value = "behaviorTrack")
@RequestMapping("/behavior-track")
@AllArgsConstructor
@Api(value = "behavior-track", tags = "行为追踪管理")
public class BehaviorTrackController {

    private BehaviorTrackService behaviorTrackService;

    /**
     * 行为追踪 （前端调用）
     * @param dto
     * @param response
     * @throws Exception
     */
    @SysLog("客户链接追踪处理")
    @GetMapping("/track")
    @ApiOperation(value = "客户链接追踪处理")
    public void handleTrack(BehaviorTrackDto dto, HttpServletResponse response) throws Exception{
        log.info("原始链接参数：{}",dto);
        behaviorTrackService.handleTrack(dto, response);
    }

    /**
     * 行为追踪 （后端远程调用）
     * @param dto
     * @param response
     * @throws Exception
     */
    @SysLog("行为追踪")
    @Inner
    @PostMapping("/track/inner")
    @ApiOperation(value = "行为追踪")
    public void handleTrackInner(@RequestBody BehaviorTrackDto dto, HttpServletResponse response) throws Exception{
        behaviorTrackService.handleTrack(dto, response);
    }

}
